package com.htfyun.guowenagingscreen;

import android.content.Context;
import android.content.SharedPreferences;


public class EinkAgingScreenSharedPref {


    private final static String EINK_SHARED_PREF_NAME = "eink_aging_screen_shared_pref";


    private final static String AGING_TIME_START = "aging_time_start";

    public static long getStartTime_ms(Context context) {

        return getLong(context, AGING_TIME_START, System.currentTimeMillis());

    }

    public static void setStartTime_ms(Context context, long ms) {

        setLong(context, AGING_TIME_START, ms);

    }

    private final static String AGING_TIME_EXIT = "aging_time_exit";

    public static long getExitTime_ms(Context context) {

        return getLong(context, AGING_TIME_EXIT, -1);

    }

    public static void setExitTime_ms(Context context, long ms) {

        setLong(context, AGING_TIME_EXIT, ms);

    }




    ////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////

    private static int getInt(Context context, String name, int defValue) {
        if (context == null) {
            return 0;
        }

        SharedPreferences sp = context.getSharedPreferences(EINK_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        return sp.getInt(name, defValue);
    }

    private static void setInt(Context context, String name, int value) {
        if (context == null) {
            return;
        }

        SharedPreferences sp = context.getSharedPreferences(EINK_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();

        editor.putInt(name, value);

        editor.apply();
    }

    private static long getLong(Context context, String name, long defValue) {
        if (context == null) {
            return 0;
        }

        SharedPreferences sp = context.getSharedPreferences(EINK_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        return sp.getLong(name, defValue);
    }

    private static void setLong(Context context, String name, long value) {
        if (context == null) {
            return;
        }

        SharedPreferences sp = context.getSharedPreferences(EINK_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(name, value);
        editor.apply();
    }

}
